
<div class="modal-body no-p">
  <div class="row">
    <div class="col-xs-12">
      <section class="panel panel-primary no-b">
        <header class="panel-heading clearfix brtl brtr">
          <div class="overflow-hidden">
            <a href="javascript:;" class="h4 show no-m pt5">会员消息</a>
          </div>
        </header>

        <div class="list-group" style="text-align: center;padding-top: 10px;">
          {%if type==1 %}
          <table width="80%" style="padding: 10px;">
              <tr style="height: 30px;">
              <td width="30%" align="right">回复内容：</td>
              <td width="70%" align="left">
                <textarea id="replyContent" class="control-group" cols="50" rows="5"></textarea>
              </td>
            </tr>
          </table>
          {% endif %}
        </div>

        <div id="list" style="padding:15px 0">
        </div>
        <div class="s_page cf clear tcdPageCode"></div>

      </section>

    </div>
  </div>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">{{ '关 闭' if type==0 else '取 消' }}</button>
  {%if type==1 %}
  <button onclick="save()" id="save" type="button" class="btn btn-primary" data-loading-text="正在提交...">确 定</button>
 {% endif %}
</div>
<script type="text/javascript">
  var is_page=true;
  function save(){
    if($("#replyContent").val()==""){
      Toast.error("内容不可为空");
      $("#replyContent").focus();
      return false;
    }
    var btn = $("#save");
    var dialog = $("#dialogDetail");
    btn.button("loading");
    $.post("/weixin/msg/reply", {id: {{msg.id}},wxid: {{msg.wxid}},openid: "{{msg.openid}}",user_id: {{msg.user_id}},content:$("#replyContent").val()}, function (data) {
      if (data.errno == 0) {
        Toast.success("发送成功");
        dialog.modal("hide");
        datatable.ajax.reload();
      } else {
        Toast.error(data.errmsg);
      }
      btn.button("reset");

    }, "json");
  }
  function pagelist(pageNum,pageSize){
    $.get("/weixin/msg/replyList", {openid: '{{msg.openid}}',pageNum:pageNum,pageSize:pageSize}, function (data) {
      var str='';
      if(data.data.length>0){
        $.each(data.data,function(i,o){
          str+='<div  style="width: 400px;padding:5px;margin-left: 40px;margin-bottom:5px;" class="alert alert-info">';
          str+= o.nickname+":"+ o.content;
          str+='</div>';
          for(var r of o.msg_reply){
          	
            str+='<div  style="width: 400px;padding:5px;margin-left: 140px;margin-bottom:5px;" class="alert alert-warning alert-dismissable">';
            str+= r.content;
            str+='</div>';
          }
        });
        $("#list").html(str);
        if(is_page){
          is_page=false;
          $(".tcdPageCode").createPage({
            pageCount:data.totalPages,
            current:data.currentPage,
            backFn:function(p){
              
              pagelist(p,pageSize);
            }
          });
        }
      }
    }, "json");
  }
  $(function(){
    pagelist(1,5);
  });
</script>
